package com.basic.business.prodRel.controller;


import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.*;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.enums.BusinessType;
import com.basic.business.prodRel.domain.TProdRelMain;
import com.basic.business.prodRel.service.ITProdRelMainService;
import com.basic.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 商品关系Controller
 *
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/prodRel")
public class TProdRelMainController extends BaseController
{
    @Resource
    private ITProdRelMainService tProdRelMainService;

    /**
     * 查询商品关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:prodRel:list')")
    @GetMapping("/list")
    public TableDataInfo list(TProdRelMain tProdRelMain)
    {
        startPage();
        List<TProdRelMain> list = tProdRelMainService.getList(tProdRelMain);
        return getDataTable(list);
    }


    /**
     * 状态变更
     */
    @PreAuthorize("@ss.hasPermi('business:prodRel:changeStatus')")
    @Log(title = "商品关系", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestParam("ids") String[] ids, @RequestParam("status") String status)
    {
        return toAjax(tProdRelMainService.updateStatusByIds(ids, status));
    }

    /**
     * 获取商品关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:prodRel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tProdRelMainService.get(id));
    }

    /**
     * 新增商品关系
     */
    @PreAuthorize("@ss.hasPermi('business:prodRel:add')")
    @Log(title = "商品关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProdRelMain tProdRelMain)
    {
        return AjaxResult.success("新增成功",tProdRelMainService.insertProdRelMain(tProdRelMain));
    }

    /**
     * 修改商品关系
     */
    @PreAuthorize("@ss.hasPermi('business:prodRel:edit')")
    @Log(title = "商品关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProdRelMain tProdRelMain)
    {
        return toAjax(tProdRelMainService.update(tProdRelMain));
    }

    /**
     * 删除商品关系
     */
    @PreAuthorize("@ss.hasPermi('business:prodRel:remove')")
    @Log(title = "商品关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tProdRelMainService.deleteByIds(ids));
    }

    /**
     * 下载模板
     */
    @PostMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response){
        tProdRelMainService.exportTemplate(response);
    }

    /**
     * 模板数据导入
     */
    @PreAuthorize("@ss.hasPermi('business:prodRel:import')")
    @Log(title = "商品关系模板数据导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importTemplate")
    public AjaxResult importTemplate(MultipartFile file, boolean coverSupport) {
        return tProdRelMainService.importTemplate(file, coverSupport);
    }

    /**
     * 刷新缓存
     */
    @PreAuthorize("@ss.hasPermi('business:prodRel:refreshCache')")
    @Log(title = "商品关系", businessType = BusinessType.CLEAN)
    @DeleteMapping("/refreshCache")
    public AjaxResult refreshCache()
    {
        tProdRelMainService.resetProdRelCache();
        return success();
    }
}
